package com.example.administrator.readbook.greendao;

import com.example.administrator.readbook.MyApplication;

/**
 * Created by Administrator on 2018/7/9.
 */

public class ReadChapterDao {
    public static void insertReadChapter(GreenDaoReadChapterBean bookBean) {
        MyApplication.getDaoInstance().getGreenDaoReadChapterBeanDao().insertOrReplace(bookBean);
    }

    public static void deleteBook(String bookId) {
//        GreenDaoBookBeanDao bookBeanDao = MyApplication.getDaoInstance().getGreenDaoBookBeanDao();
//        bookBeanDao.getDatabase().execSQL("delete from GREEN_DAO_BOOK_BEAN where bookId = " + bookId);
        MyApplication.getDaoInstance().getGreenDaoReadChapterBeanDao().deleteByKey(bookId);
    }

    public static void deleteBook(GreenDaoReadChapterBean bookBean) {
        MyApplication.getDaoInstance().getGreenDaoReadChapterBeanDao().delete(bookBean);
    }


    public static void updateBook(String readChpaterName) {
        GreenDaoReadChapterBean bookBean = new GreenDaoReadChapterBean();
        bookBean.setReadChapterBookReadChapter(readChpaterName);
        MyApplication.getDaoInstance().getGreenDaoReadChapterBeanDao().update(bookBean);
    }

    public static GreenDaoReadChapterBean queryReadChapter(String bookName) {
        return MyApplication.getDaoInstance().getGreenDaoReadChapterBeanDao().queryBuilder().where(GreenDaoReadChapterBeanDao.Properties.ReadChapterId.eq(bookName)).unique();
    }

}
